package com.szrt.java.day20161223.wrl.demo05;

import org.junit.Test;

public class ForDemo {

	/**
	 * for分三步走：都写着"()"中，"(;;)"
	 * 	1）、定义从哪里开始	包含端点
	 * 	2）、定义到哪里结束	包含端点
	 * 	3）、每次的变化是多少	
	 * 
	 * 1+...+10=?;步长为1
	 */
	@Test
	public void for01() {
		int sum = 0;
		for (int begin = 1; begin <= 10; begin++) {
			sum += begin;
		}
		System.out.println(sum);
	}
	
	@Test
	public void for02() {
		int sum = 0;
		for (int begin = 19; begin <= 99; begin += 20) {
			sum += begin;
		}
		System.out.println(sum);
	}
	
	/**
	 * **********
	 * **********
	 * **********
	 * **********
	 * **********
	 */
	@Test
	public void for03() {
		for (int outer = 1; outer <= 5; outer++) {
			for (int begin = 1; begin <= 10; begin++) {
				System.out.print("*");
			}
			//换行
			System.out.println();
		}
	}
	
	/**
	 * *
	 * **
	 * ***
	 * ****
	 * *****
	 */
	@Test
	public void for04() {
		for (int i = 1; i <= 5; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print("*");
			}
			//换行
			System.out.println();
		}
	}
	
	/**
	 * ******
	 * *****
	 * ****
	 * ***
	 * **
	 * *
	 */
	@Test
	public void for05() {
		for (int i = 1; i <= 6; i++) {
			for (int j = 1; j <= 7-i; j++) {
				System.out.print("*");
			}
			//换行
			System.out.println();
		}
	}
	
	/**
	 *     *
	 *    ***
	 *   *****
	 *  *******
	 *   *****
	 *    ***
	 *     *
	 */
	@Test
	public void for06() {
		for(int hang = 1;hang<=4;hang++){
			//1.先打印空格 space
			for(int sp=1;sp<=4-hang;sp++){
				System.out.print(" ");
			}
			//2.打印星星
			for(int star=1;star<=2*hang-1;star++){
				System.out.print("*");
			}
			//3.打印换行
			System.out.println();
		}
		
		//--打印下半部分
		for(int hang=1;hang<=3;hang++){
			//空格
			for(int sp=1;sp<=hang;sp++){
				System.out.print(" ");
			}
			//星星
			for(int star=1;star<=7-2*hang;star++){
				System.out.print("*");
			}
			//换行
			System.out.println();
		}
	}
	
	@Test
	public void table9x9(){
		for(int outer=1; outer<=9; outer++){
			for(int inner=1; inner<=outer; inner++){
				System.out.print(outer+"x"+inner+"="+(outer*inner)+"\t");
			}
			System.out.println();
		}
	}
}
